/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.maestros;

import DAO.ParametroDAO;
import Model.Empleado;
import Model.Parametro;
import Model.Perfil;
import Model.Turno;
import Presenter.EmpleadoPresenter;
import Presenter.EnvioPedidoPresenter;
import Presenter.PerfilPresenter;
import Presenter.TurnoPresenter;
import Principals.Validadores;
import View.components.Index;
import java.io.File;
import java.util.List;
import javax.swing.JDesktopPane;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author walter
 */
public class Frm_RegistrarEmpleado extends javax.swing.JDesktopPane {

    /**
     * Creates new form Frm_BuscarEmpleado
     */
    Validadores val = new Validadores();
    //File archivoCarga = new File();
    
    public Frm_RegistrarEmpleado() {
        initComponents();
        EnvioPedidoPresenter.actualizarEnvioPedido();
        val.desactivarAccionPegar(txtApellidoMaterno);
        val.desactivarAccionPegar(txtApellidoPaterno);
        val.desactivarAccionPegar(txtNombre);
        val.desactivarAccionPegar(txtNroDocId);
        val.desactivarAccionPegar(txtTelefono);
        val.desactivarAccionPegar(txtNroBrevete);
        val.desactivarAccionPegar(txtDireccion);
        val.desactivarAccionPegar(txtCorreoElectronico);
        val.desactivarAccionPegar(txtArchivoCarga);
        
        // Combo de perfiles
        List<Perfil> lstPerfil = PerfilPresenter.listPerfil();
        for (Perfil p : lstPerfil) {
            cbxPerfil.addItem(p);
        }
        // Combo de turnos
        List<Turno> lstTurno = TurnoPresenter.listTurno();
        for (Turno t : lstTurno) {
            cbxTurno.addItem(t);
        }
        // Combo de tipo de vehiculo
        List<Parametro> lstTipoVehiculo = ParametroDAO.getTipoVehiculos();
        for (Parametro p : lstTipoVehiculo) {
            cbxTipoVehiculo.addItem(p);
        }
        //Activar campos de conductor
        activarCamposConductor(false);
        btnCargarEmpleado.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar2 = new javax.swing.JToolBar();
        btnToolNuevo = new javax.swing.JButton();
        btnToolModificar = new javax.swing.JButton();
        btnToolAlmacenar = new javax.swing.JButton();
        btnToolEliminar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        btnToolLimpar = new javax.swing.JButton();
        btnToolBuscar = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        btnToolCancelar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        pnlBuscarEmpleado = new javax.swing.JPanel();
        lblApellidoPaterno = new javax.swing.JLabel();
        txtApellidoPaterno = new javax.swing.JTextField();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblApellidoMaterno = new javax.swing.JLabel();
        txtApellidoMaterno = new javax.swing.JTextField();
        lblDocIdentidad = new javax.swing.JLabel();
        txtNroDocId = new javax.swing.JTextField();
        lblTelefono = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        lblCorreoElectronico = new javax.swing.JLabel();
        txtCorreoElectronico = new javax.swing.JTextField();
        lblDireccion = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        lblPerfilEmpleado = new javax.swing.JLabel();
        lblTurno = new javax.swing.JLabel();
        cbxTurno = new javax.swing.JComboBox();
        lblTipoVehiculo = new javax.swing.JLabel();
        cbxTipoVehiculo = new javax.swing.JComboBox();
        cbxPerfil = new javax.swing.JComboBox();
        lblNroBrevete = new javax.swing.JLabel();
        txtNroBrevete = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        lblArchivoCarga = new javax.swing.JLabel();
        txtArchivoCarga = new javax.swing.JTextField();
        btnSeleccionarArchivo = new javax.swing.JButton();
        btnCargarEmpleado = new javax.swing.JButton();
        barrita = new javax.swing.JProgressBar();

        setPreferredSize(new java.awt.Dimension(665, 439));

        jToolBar2.setFloatable(false);
        jToolBar2.setBorderPainted(false);

        btnToolNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Nuevo.png"))); // NOI18N
        btnToolNuevo.setEnabled(false);
        btnToolNuevo.setFocusable(false);
        btnToolNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolNuevoActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolNuevo);

        btnToolModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Editar.png"))); // NOI18N
        btnToolModificar.setEnabled(false);
        btnToolModificar.setFocusable(false);
        btnToolModificar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolModificar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolModificarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolModificar);

        btnToolAlmacenar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Guardar.png"))); // NOI18N
        btnToolAlmacenar.setFocusable(false);
        btnToolAlmacenar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolAlmacenar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolAlmacenar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolAlmacenarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolAlmacenar);

        btnToolEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Eliminar.png"))); // NOI18N
        btnToolEliminar.setEnabled(false);
        btnToolEliminar.setFocusable(false);
        btnToolEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolEliminarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolEliminar);
        jToolBar2.add(jSeparator3);

        btnToolLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Limpiar.png"))); // NOI18N
        btnToolLimpar.setFocusable(false);
        btnToolLimpar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolLimpar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolLimparActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolLimpar);

        btnToolBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Buscar.png"))); // NOI18N
        btnToolBuscar.setFocusable(false);
        btnToolBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolBuscarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolBuscar);
        jToolBar2.add(jSeparator4);

        btnToolCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Cancelar.png"))); // NOI18N
        btnToolCancelar.setToolTipText("");
        btnToolCancelar.setFocusable(false);
        btnToolCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolCancelarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolCancelar);

        pnlBuscarEmpleado.setBorder(javax.swing.BorderFactory.createTitledBorder("Registrar nuevo empleado"));

        lblApellidoPaterno.setText("Apellido Paterno*:");

        txtApellidoPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidoPaternoKeyTyped(evt);
            }
        });

        lblNombre.setText("Nombre*:");

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });

        lblApellidoMaterno.setText("Apellido Materno*:");

        txtApellidoMaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidoMaternoKeyTyped(evt);
            }
        });

        lblDocIdentidad.setText("Doc. de Identidad*:");

        txtNroDocId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNroDocIdKeyTyped(evt);
            }
        });

        lblTelefono.setText("Teléfono*:");

        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });

        lblCorreoElectronico.setText("Correo electrónico*:");

        txtCorreoElectronico.setToolTipText("");
        txtCorreoElectronico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCorreoElectronicoKeyTyped(evt);
            }
        });

        lblDireccion.setText("Direccion*:");

        txtDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDireccionKeyTyped(evt);
            }
        });

        lblPerfilEmpleado.setText("Perfil*:");

        lblTurno.setText("Turno*:");

        lblTipoVehiculo.setText("Tipo de vehículo*:");

        cbxPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxPerfilActionPerformed(evt);
            }
        });

        lblNroBrevete.setText("Nro. de brevete*:");

        txtNroBrevete.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNroBreveteKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout pnlBuscarEmpleadoLayout = new javax.swing.GroupLayout(pnlBuscarEmpleado);
        pnlBuscarEmpleado.setLayout(pnlBuscarEmpleadoLayout);
        pnlBuscarEmpleadoLayout.setHorizontalGroup(
            pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPerfilEmpleado)
                            .addComponent(lblTipoVehiculo))
                        .addGap(333, 333, 333)
                        .addComponent(txtNroBrevete))
                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNombre)
                            .addComponent(lblApellidoPaterno)
                            .addComponent(lblDireccion)
                            .addComponent(lblApellidoMaterno))
                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                                            .addComponent(txtApellidoMaterno))))
                                .addGap(41, 41, 41)
                                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addComponent(lblCorreoElectronico)
                                        .addGap(18, 18, 18)
                                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbxTurno, 0, 186, Short.MAX_VALUE)
                                            .addComponent(txtCorreoElectronico)))
                                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblDocIdentidad)
                                            .addComponent(lblTelefono))
                                        .addGap(18, 18, 18)
                                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtTelefono)
                                            .addComponent(txtNroDocId, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
                                        .addGap(0, 0, Short.MAX_VALUE))))
                            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addComponent(cbxPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBuscarEmpleadoLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbxTipoVehiculo, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(42, 42, 42)
                                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblNroBrevete)
                                    .addComponent(lblTurno))))))
                .addContainerGap())
        );
        pnlBuscarEmpleadoLayout.setVerticalGroup(
            pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblApellidoPaterno)
                    .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDocIdentidad)
                    .addComponent(txtNroDocId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblApellidoMaterno)
                    .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCorreoElectronico)
                    .addComponent(txtCorreoElectronico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDireccion)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblPerfilEmpleado)
                        .addComponent(cbxPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblTurno))
                    .addComponent(cbxTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTipoVehiculo)
                        .addComponent(cbxTipoVehiculo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtNroBrevete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblNroBrevete))
                .addContainerGap(114, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Carga individual", pnlBuscarEmpleado);

        lblArchivoCarga.setText("Archivo de carga:");

        txtArchivoCarga.setEnabled(false);

        btnSeleccionarArchivo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Examinar.png"))); // NOI18N
        btnSeleccionarArchivo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeleccionarArchivoActionPerformed(evt);
            }
        });

        btnCargarEmpleado.setText("Cargar");
        btnCargarEmpleado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCargarEmpleadoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnCargarEmpleado)
                .addGap(320, 320, 320))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(100, 100, 100)
                        .addComponent(lblArchivoCarga)
                        .addGap(18, 18, 18)
                        .addComponent(txtArchivoCarga, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnSeleccionarArchivo))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(257, 257, 257)
                        .addComponent(barrita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(183, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSeleccionarArchivo)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblArchivoCarga)
                        .addComponent(txtArchivoCarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCargarEmpleado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(barrita, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(242, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Carga masiva", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cambiarVista(JDesktopPane panel) {
        ((Index) (this.getTopLevelAncestor())).changeDesktopPane(panel);
    }

    private void btnToolNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolNuevoActionPerformed
    }//GEN-LAST:event_btnToolNuevoActionPerformed

    private void btnToolModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolModificarActionPerformed
    }//GEN-LAST:event_btnToolModificarActionPerformed

    private void btnToolBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolBuscarActionPerformed
        cambiarVista(new Frm_BuscarEmpleado());
    }//GEN-LAST:event_btnToolBuscarActionPerformed

    private void btnToolEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolEliminarActionPerformed
        cambiarVista(new Frm_EliminarEmpleado());
    }//GEN-LAST:event_btnToolEliminarActionPerformed

    private void btnToolCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolCancelarActionPerformed
        cambiarVista(new Frm_BuscarEmpleado());
    }//GEN-LAST:event_btnToolCancelarActionPerformed

    @SuppressWarnings("UnusedAssignment")
    private void btnToolAlmacenarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolAlmacenarActionPerformed

        String apPat = txtApellidoPaterno.getText();
        String apMat = txtApellidoMaterno.getText();
        String nombres = txtNombre.getText();
        String nroDoc = txtNroDocId.getText();
        String correo = txtCorreoElectronico.getText();
        String telefono = txtTelefono.getText();
        String direccion = txtDireccion.getText();
        Turno turno = (Turno) cbxTurno.getSelectedItem();
        Parametro tipoVehiculo = (Parametro) cbxTipoVehiculo.getSelectedItem();
        String nroBrevete = txtNroBrevete.getText();
        Perfil perfil = (Perfil) cbxPerfil.getSelectedItem();

        String mensaje_error = "";
        boolean error=false;
        //Campos obligatorios estén llenos
        if ("".equals(apPat) || "".equals(apMat) || "".equals(nombres) || "".equals(nroDoc)
                || "".equals(correo) || "".equals(telefono) || "".equals(direccion) 
                || (perfil.getNombre().equals("Conductor") && nroBrevete.isEmpty())){    
            mensaje_error="Debe ingresar todos los campos obligatorios.";
            error=true;
        }
        
        //DNI válido
        if (!nroDoc.isEmpty() && nroDoc.length() != 8){
            if (error) mensaje_error=mensaje_error.concat("\n");            
            mensaje_error=mensaje_error.concat("Debe ingresar un Documento de Identidad válido.");
            error=true;
        }
        
        //telefono válido
        if (!telefono.isEmpty() && telefono.length() < 7){
            if (error) mensaje_error=mensaje_error.concat("\n");            
            mensaje_error=mensaje_error.concat("Debe ingresar un Teléfono válido.");
            error=true;
        }
        
        //Correo electrónico válido
        if (!correo.isEmpty() && !val.validaEmail(correo)) {
            if (error) mensaje_error=mensaje_error.concat("\n");            
            mensaje_error=mensaje_error.concat("Debe ingresar un Correo Electrónico válido.");
            error=true;
        }
        
        //Brevete válido
        if (perfil.getNombre().equals("Conductor") && nroBrevete.length() != 9){
            if (error) mensaje_error=mensaje_error.concat("\n");            
            mensaje_error=mensaje_error.concat("Debe ingresar un Número de brevete válido.");
            error=true;
        }
        
        if (error) {
               JOptionPane.showMessageDialog(this, mensaje_error);
        } else {
                    int respuesta = JOptionPane.showConfirmDialog(this, "Está seguro de registrar al empleado", "Guardar", JOptionPane.OK_CANCEL_OPTION);
                    switch (respuesta) {
                        case JOptionPane.OK_OPTION:
                            Empleado e=EmpleadoPresenter.existeDocId(nroDoc);
                            if(e!=null)
                            {
                                String msj="El Documento de Identidad ya se encuentra registrado para el empleado:\n";
                                String emp=e.getNombres()+' '+e.getApellidoPaterno()+' '+e.getApellidoMaterno();
                                msj=msj.concat(emp);
                                JOptionPane.showMessageDialog(this, msj);
                            }
                            else{
                                EmpleadoPresenter.registrarEmpleado(apPat, apMat, nombres, nroDoc, correo, telefono, direccion, turno, tipoVehiculo, perfil, nroBrevete);
                                JOptionPane.showMessageDialog(this, "Se registró al empleado.");
                                cambiarVista(new Frm_BuscarEmpleado());
                            }
                            break;
                        case JOptionPane.CANCEL_OPTION:
                            break;
                    }            

        }
    }//GEN-LAST:event_btnToolAlmacenarActionPerformed

    private void cbxPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxPerfilActionPerformed
        if (cbxPerfil.getSelectedItem().toString().equals("Conductor")) {
            activarCamposConductor(true);
        } else {
            activarCamposConductor(false);
        }
    }//GEN-LAST:event_cbxPerfilActionPerformed

    private void txtApellidoPaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoPaternoKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtApellidoPaterno.getText());
    }//GEN-LAST:event_txtApellidoPaternoKeyTyped

    private void txtApellidoMaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoMaternoKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtApellidoMaterno.getText());
    }//GEN-LAST:event_txtApellidoMaternoKeyTyped

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtNombre.getText());
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtNroDocIdKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroDocIdKeyTyped
        val.validaSoloNumeros(evt);
        val.validaMaxSize(evt, 8, txtNroDocId.getText());
    }//GEN-LAST:event_txtNroDocIdKeyTyped

    private void txtCorreoElectronicoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCorreoElectronicoKeyTyped
        val.validaCaracteresEmail(evt);
        val.validaMaxSize(evt, 40, txtCorreoElectronico.getText());
    }//GEN-LAST:event_txtCorreoElectronicoKeyTyped

    private void txtDireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDireccionKeyTyped
        val.validaCaracteresDirec(evt);
        val.validaMaxSize(evt, 40, txtDireccion.getText());
    }//GEN-LAST:event_txtDireccionKeyTyped

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped
        val.validaSoloNumeros(evt);
        val.validaMaxSize(evt, 10, txtTelefono.getText());
    }//GEN-LAST:event_txtTelefonoKeyTyped

    private void txtNroBreveteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroBreveteKeyTyped
        val.validaSoloNumerosLetras(evt);
        val.validaMaxSize(evt, 9, txtNroBrevete.getText());
    }//GEN-LAST:event_txtNroBreveteKeyTyped

    private void btnToolLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolLimparActionPerformed
        txtApellidoMaterno.setText("");
        txtApellidoPaterno.setText("");
        txtCorreoElectronico.setText("");
        txtDireccion.setText("");
        txtNombre.setText("");
        txtNroDocId.setText("");
        txtTelefono.setText("");
        txtNroBrevete.setText("");
    }//GEN-LAST:event_btnToolLimparActionPerformed

    private void btnSeleccionarArchivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarArchivoActionPerformed
        JFileChooser jfcSeleccionarArchvivo = new JFileChooser();
        int status = jfcSeleccionarArchvivo.showOpenDialog(null);
        if (status == JFileChooser.APPROVE_OPTION) {
            File selectedFile = new File( jfcSeleccionarArchvivo.getSelectedFile().getAbsolutePath() ) ;
            //      System.out.println(selectedFile.getParent());
            //      System.out.println(selectedFile.getName());
            txtArchivoCarga.setText(selectedFile.getAbsolutePath() );
            btnCargarEmpleado.setEnabled(true);
        } else if (status == JFileChooser.CANCEL_OPTION) {
            System.out.println(JFileChooser.CANCEL_OPTION);
            btnCargarEmpleado.setEnabled(false);
        }
    }//GEN-LAST:event_btnSeleccionarArchivoActionPerformed

    private void btnCargarEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCargarEmpleadoActionPerformed
        String path = txtArchivoCarga.getText() ;
        EmpleadoPresenter.barrita = barrita ;
        EmpleadoPresenter.registrarEmpleado( path ) ; 
        JOptionPane.showMessageDialog( this , "Se registraron los empleados con éxito" ) ;
        btnCargarEmpleado.setEnabled(false);
        txtArchivoCarga.setText("");
        cambiarVista(new Frm_BuscarEmpleado());
    }//GEN-LAST:event_btnCargarEmpleadoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar barrita;
    private javax.swing.JButton btnCargarEmpleado;
    private javax.swing.JButton btnSeleccionarArchivo;
    private javax.swing.JButton btnToolAlmacenar;
    private javax.swing.JButton btnToolBuscar;
    private javax.swing.JButton btnToolCancelar;
    private javax.swing.JButton btnToolEliminar;
    private javax.swing.JButton btnToolLimpar;
    private javax.swing.JButton btnToolModificar;
    private javax.swing.JButton btnToolNuevo;
    private javax.swing.JComboBox cbxPerfil;
    private javax.swing.JComboBox cbxTipoVehiculo;
    private javax.swing.JComboBox cbxTurno;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JLabel lblApellidoMaterno;
    private javax.swing.JLabel lblApellidoPaterno;
    private javax.swing.JLabel lblArchivoCarga;
    private javax.swing.JLabel lblCorreoElectronico;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblDocIdentidad;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblNroBrevete;
    private javax.swing.JLabel lblPerfilEmpleado;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JLabel lblTipoVehiculo;
    private javax.swing.JLabel lblTurno;
    private javax.swing.JPanel pnlBuscarEmpleado;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtArchivoCarga;
    private javax.swing.JTextField txtCorreoElectronico;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNroBrevete;
    private javax.swing.JTextField txtNroDocId;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables

    private void activarCamposConductor(boolean activo) {
        lblTipoVehiculo.setEnabled(activo);
        cbxTipoVehiculo.setEnabled(activo);
        lblNroBrevete.setEnabled(activo);
        txtNroBrevete.setEnabled(activo);
    }
}
